//
//  EBMBaseCollectionView.m
//  eBondMall
//
//  Created by apple on 2020/3/31.
//  Copyright © 2020 zhaoshijie. All rights reserved.
//

#import "EBMBaseCollectionView.h"

@implementation EBMBaseCollectionView


- (void)awakeFromNib
{
    [super awakeFromNib];
    
    // 创建视图
    [self baseInitView];
    
}


- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout
{
    self = [super initWithFrame:frame collectionViewLayout:layout];
    
    if(self)
    {
        // 创建视图
        [self baseInitView];
        
    }
    return self;
    
}


#pragma mark -- --------------------创建视图--------------------
// 创建视图
- (void)baseInitView
{
    
    self.backgroundColor = RGBCOLOR16_F1F2F3;
    
    self.emptyDataSetSource = self;
    self.emptyDataSetDelegate = self;
    
}



/// 添加上下拉刷新加载
/// @param headrRefreshingBlock 下拉刷新
/// @param footerRefreshingBlock 上拉加载
- (void)loadTableMjHeaderWithHeadrRefreshingBlock:(MJRefreshComponentRefreshingBlock)headrRefreshingBlock
                            footerRefreshingBlock:(MJRefreshComponentRefreshingBlock)footerRefreshingBlock
{
    if(headrRefreshingBlock)
    {
        //  添加上下拉刷新加载
        self.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:headrRefreshingBlock];
        
    }
    
    if(footerRefreshingBlock)
    {
        //  添加上下拉刷新加载
        self.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:footerRefreshingBlock];
    }
    
}

//  重写刷新
- (void)reloadData
{
    [super reloadData];
    
    //  tableView结束刷新
    [self baseEndRefresh];
    
    //  刷新数据
    [self reloadEmptyDataSet];
    
}


/// tableView结束刷新
- (void)baseEndRefresh
{
    if(self.mj_header)
    {
        [self.mj_header endRefreshing];
    }
    
    if(self.mj_footer)
    {
        [self.mj_footer endRefreshing];
    }
    
}


/// 注册cell nib
/// @param className cell名称
- (void)registerNibWithCellClassName:(NSString *)className
{
    [self registerNib:[UINib nibWithNibName:className bundle:nil] forCellWithReuseIdentifier:className];
}


/// 注册cell class
/// @param class cell的类
- (void)registerClassWithCellClass:(Class)class
{
    [self registerClass:class forCellWithReuseIdentifier:NSStringFromClass(class)];
}



#pragma mark ----------DZNEmptyDataSetSource 代理方法----------
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
    UIImage *image = [UIImage imageNamed:@"Bond_Main_Null"];
    
    return image;
    
}

- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
    NSString *title = @"暂无数据";
    NSDictionary *attributes = @{
                                 NSFontAttributeName:Font_14,
                                 NSForegroundColorAttributeName:RGBCOLOR16_888888
                                 };
    return [[NSAttributedString alloc] initWithString:title attributes:attributes];
    
}


- (void)emptyDataSet:(UIScrollView *)scrollView didTapView:(UIView *)view
{
    if(self.mj_header)
    {
        [self.mj_header beginRefreshing];
    }
    
    
}

@end
